package net.xo68.destiny.manager.mapper;


import net.xo68.destiny.manager.entity.NodeMonitor;
import org.apache.ibatis.annotations.*;
import java.util.List;

/** 
 * NodeMonitor mybatis mapper
 * @author wuxie(16349023@qq.com)
 * @date 2020年12月14日 11:10:13
 *
 */
public interface NodeMonitorMapper {


	
	@Select("SELECT * FROM job_node_monitor WHERE id = #{id}")
    @Results(value = { 
    @Result(id = true, column = "id", property = "id"),
        @Result(column = "node_host", property = "nodeHost"),
        @Result(column = "node_type_name", property = "nodeTypeName"),
        @Result(column = "work_group_name", property = "workGroupName"),
        @Result(column = "cpu_usage", property = "cpuUsage"),
        @Result(column = "memory_usage", property = "memoryUsage"),
        @Result(column = "load_average", property = "loadAverage"),
        @Result(column = "reg_time", property = "regTime")
    })
    NodeMonitor find(@Param("id") Long id);
	
	@Select("SELECT * FROM job_node_monitor")
    @Results(value = { 
    @Result(id = true, column = "id", property = "id"),
        @Result(column = "node_host", property = "nodeHost"),
        @Result(column = "node_type_name", property = "nodeTypeName"),
        @Result(column = "work_group_name", property = "workGroupName"),
        @Result(column = "cpu_usage", property = "cpuUsage"),
        @Result(column = "memory_usage", property = "memoryUsage"),
        @Result(column = "load_average", property = "loadAverage"),
        @Result(column = "reg_time", property = "regTime")
    })
    List<NodeMonitor> list();
	
	@Insert("insert into job_node_monitor (id ,node_host ,node_type_name ,work_group_name ,cpu_usage ,memory_usage ,load_average ,reg_time ) values (#{id} , #{nodeHost} , #{nodeTypeName} , #{workGroupName} , #{cpuUsage} , #{memoryUsage} , #{loadAverage} , #{regTime}  )")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(NodeMonitor nodeMonitor);
	
	@Update({"update job_node_monitor set",
      " node_host=#{nodeHost}, node_type_name=#{nodeTypeName}, work_group_name=#{workGroupName}, cpu_usage=#{cpuUsage}, memory_usage=#{memoryUsage}, load_average=#{loadAverage}, reg_time=#{regTime} ",
      "where id = #{id}"
    })
    int update(NodeMonitor nodeMonitor);

	@Delete("delete FROM job_node_monitor WHERE id = #{id}")
	int delete(@Param("id") Long id);

    @Delete("delete FROM job_node_monitor  where reg_time < DATE_ADD(NOW(),INTERVAL -#{timeoutSecond} SECOND)")
	int removeExpired(@Param("timeoutSecond") long timeoutSecond);
}